package com.tuling.vipes.controller;



import com.tuling.vipes.service.ElasticsearchDeleteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @创建人: Mhh
 * @创建时间: 2021/12/10
 * @描述: 删除类
 */
@RestController
@RequestMapping("/elasticSearch/delete")
public class ElasticsearchDeleteController {

    @Autowired
    private ElasticsearchDeleteService elasticsearchDeleteService;

    /**
     * @param clazz : 删除的哪个索引(从传入对象中的@Document注解中indexName属性获取)
     * @return java.lang.Boolean
     * @explain : 删除索引
     * @Author Mhh
     * @Date 2021/12/27 14:27
     */
    @PostMapping("deleteIndex")
    public Boolean deleteIndex(Class<?> clazz) {
        return elasticsearchDeleteService.deleteIndex(clazz);
    }


    /**
     * @param id         : 要删除的主键id
     * @param entityType : 删除的哪个索引的数据(从传入对象中的@Document注解中indexName属性获取)
     * @return java.lang.Boolean
     * @throws
     * @Author Mhh
     * @Date 2021/12/9 10:40
     */
    @PostMapping("deleteById")
    public Boolean delete(@RequestParam("id") String id, Class<?> entityType) {
        return elasticsearchDeleteService.delete(id, entityType);
    }

    /**
     * @param entity : 这个实体对象必须是被@Document注解且有indexName属性值) 以及主键必须有值,其它参数有无都没关系(和用主键id删除没区别)
     * @return java.lang.Boolean
     * @throws
     * @Author Mhh
     * @Date 2021/12/9 10:40
     */
    @PostMapping("delete")
    public Boolean delete(Object entity) {
        return elasticsearchDeleteService.delete(entity);
    }



    /**
     * @param query  : 删除掉被query所搜索到的所有数据。
     * @param entity : 删除的哪个索引的数据(从传入对象中的@Document注解中indexName属性获取)
     * @return java.lang.Boolean
     * @explain :
     * @Author Mhh
     * @Date 2021/12/27 14:22
     */

    @PostMapping("deleteByQuery")
    public Boolean delete(Query query, Class<?> entity) {
        return elasticsearchDeleteService.delete(query, entity);
    }

}

